package com.atguigui.leetcode;

import java.util.Random;

/**
 * 1374.生成每种字符都是奇数个的字符串
 * Project: leetcode
 * Package: com.atguigui.leetcode
 * Version: 1.0
 * <p>
 * Created by  wangjiaxin  on 2022/8/1 00:16
 */
public class P1374GenerateAStringWithCharactersThatHaveOddCounts {
    public static void main(String[] args) {
        Solution solution = new P1374GenerateAStringWithCharactersThatHaveOddCounts().new Solution();
        solution.generateTheString(12);
        // TO TEST
    }

    //leetcode submit region begin(Prohibit modification and deletion)
    class Solution {
        public String generateTheString(int n) {
            char[] chr = {'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z'};

            Random rand = new Random();
            int nums = rand.nextInt(chr.length);

            StringBuilder sb = new StringBuilder();
            if (n % 2 == 0) {
                //偶数
                for (int i = 0; i < n - 1; i++) {
                    sb.append(chr[nums]);
                }

                char c = chr[rand.nextInt(chr.length)];
                while (c == chr[nums]) {
                    c = chr[rand.nextInt(chr.length)];
                }

                sb.append(c);
            } else {
                for (int i = 0; i < n; i++) {
                    sb.append(chr[nums]);
                }
            }

            return sb.toString();
        }
    }
}
